#include<iostream>
#include<queue>
#include<vector>
using namespace std;
const int N = 515;//逆天了给510全都过不了给515就行了
vector<int> edges[N];
int n;
int in[N];
bool st[N];
int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		int x = 0;
		cin >> x;
		st[x] = true;
		int t = 0;
		cin >> t;
		while (t--)
		{
			int y = 0;
			cin >> y;
			edges[x].push_back(y);
			in[y]++;
		}
	}
	queue<int> q;

	for (int i = 0;i <= 510;i++)
	{
		if (in[i] == 0 && st[i] ==  true)
		{
			q.push(i);
		}
	}
	int ret = 0;
	while (q.size())
	{
		int x = q.front();
		ret++;//砸掉的数量
		q.pop();
		for (auto y : edges[x])
		{
			if (st[y] == true)
			{
				in[y]--;
				if (in[y] == 0) q.push(y);
			}
		}
	}
	if (ret == n) cout << "YES" << endl;
	else cout << n-ret << endl;
	return 0;

}